package it.stessaro.lostcities.collection.pile;

import it.stessaro.lostcities.collection.Card;
import it.stessaro.lostcities.core.Costants;

//Deck
public class Deck extends CardStack{

	private Hand player_hand, pc_hand;
	private static final long serialVersionUID = 1L;
	public Deck(){
	
		int[] arr_numbers = {1,1,1,2,3,4,5,6,7,8,9,10,
				1,1,1,2,3,4,5,6,7,8,9,10,
				1,1,1,2,3,4,5,6,7,8,9,10,
				1,1,1,2,3,4,5,6,7,8,9,10,
				1,1,1,2,3,4,5,6,7,8,9,10};
		//prepare the deck
		for (int i = 0; i < arr_numbers.length; i++) {
			if (i<=11) {
				this.add(new Card(arr_numbers[i],Costants.WHITE));
			} else if(12<=i && i<=23){
				this.add(new Card(arr_numbers[i], Costants.RED));
			}else if(24<=i && i<=35){
				this.add(new Card(arr_numbers[i], Costants.GREEN));
			}else if(36<=i && i<=47){
				this.add(new Card(arr_numbers[i], Costants.YELLOW));
			}else if(48<=i && i<=59){
				this.add(new Card(arr_numbers[i], Costants.BLUE));
			}
		}
		//shuffle the deck
		this.shuffle();
		
		player_hand = new Hand();
		pc_hand = new Hand();
		
		//Give cards
		for (int i = 0; i < 8; i++) {
			player_hand.add(this.pop());
			pc_hand.add(this.pop());
		}

		//sort hands
		player_hand.sort();
		pc_hand.sort();
	}
	
	public Hand getPlayerHand(){
		return player_hand;
	}
	
	public Hand getHandPC(){
		return pc_hand;
	}
	
	public boolean playerDrawCard(){
		if (this.size() == 0) {
			return false;
		}
		Card draw_card = this.pop();
		player_hand.add(draw_card);
		return true;
	}
	
	public boolean pcDrawCard(){
		if (this.size() == 0) {
			return false;
		}
		Card draw_card = this.pop();
		pc_hand.add(draw_card);
		return true;
	}
	
	public void playerHandSort(){
		player_hand.sort();
	}
}